package com.exam.pay_local_sign;

import com.exam.pay_local_sign.alipay.OrderInfoUtil2_0;
import com.exam.pay_local_sign.wxpay.WXConstants;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;

/**
 * PayLocalSignPlugin
 */
public class PayLocalSignPlugin implements FlutterPlugin, MethodCallHandler {
    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
        final MethodChannel channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "pay_local_sign");
        channel.setMethodCallHandler(new PayLocalSignPlugin());
    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
    }

    public static void registerWith(Registrar registrar) {
        final MethodChannel channel = new MethodChannel(registrar.messenger(), "pay_local_sign");
        channel.setMethodCallHandler(new PayLocalSignPlugin());
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
        if (call.method.equals("getAlipayOrderInfo")) {//签名支付宝订单信息
            String id = call.argument("id");
            String title = call.argument("title");
            String des = call.argument("des");
            result.success(OrderInfoUtil2_0.getOrderInfo(id, title, des));
        } else if (call.method.equals("getWXAppId")) {//获取微信appid
            result.success(WXConstants.APP_ID);
        } else if (call.method.equals("getWxOrderInfo")) {//获取微信下单信息
            Map<String, String> val = new HashMap<>();
            val.put("abc", "子线程调用WXPayUtil.wxUniteOrder()");
            result.success(val);
        } else {
            result.notImplemented();
        }
    }


}
